<template>
  <div style="height:100%;width:100%">
    <el-row class="mainContent" >
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true"  :model="filters" size="small" style="text-align:left;" ref="filters">
          <el-form-item >
            <el-input v-model="filters.serialnumber" placeholder="流水号" clearable></el-input>
          </el-form-item>
          <el-form-item >
            <el-input v-model="filters.keyword" placeholder="手机号" clearable></el-input>
          </el-form-item>
          <!--<el-form-item>-->
            <!--<el-select v-model="filters.state" placeholder="状态" clearable>-->
              <!--<el-option-->
                <!--v-for="item in options"-->
                <!--:key="item.value"-->
                <!--:label="item.label"-->
                <!--:value="item.value">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <el-form-item>
            <div class="block">
              <el-date-picker
                v-model="filters.begtime"
                type="datetime"
                placeholder="申请开始日期">
              </el-date-picker>
              <el-date-picker
                v-model="filters.endtime"
                type="datetime"
                placeholder="申请结束日期">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"  @click="getUsers">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <!--列表-->
      <el-table :data="users" highlight-current-row v-loading="listLoading" style="width: 100%;">
        <el-table-column prop="serialnumber" label="流水号">
        </el-table-column>
        <el-table-column prop="mobile" label="手机号">
        </el-table-column>
        <el-table-column prop="username" label="用户名"  >
        </el-table-column>
        <el-table-column prop="realname" label="姓名"  >
        </el-table-column>
        <el-table-column prop="applyTime" label="申请时间"  >
        </el-table-column>
        <el-table-column prop="amount" label="申请金额"  >
        </el-table-column>
        <el-table-column prop="bankCardbranch" label="银行"  >
        </el-table-column>
        <el-table-column prop="bankCardNo" label="银行卡号"  >
        </el-table-column>
        <el-table-column  label="状态"  >
          <template slot-scope="scope">
            {{scope.row.state | stateFormat}}
          </template>
        </el-table-column>
        <el-table-column  label="操作" width="150" v-if="$store.state.routes.routes.yhtxsdOperate || $store.state.routes.routes.yhtxqxOperate">
          <template slot-scope="scope">
            <el-button v-if="$store.state.routes.routes.yhtxsdOperate"
              size="mini"
              type="text"
              @click="handDialog(scope.$index, scope.row)" :disabled="scope.row.state!=10">手动打款</el-button>
            <!--<el-button-->
              <!--size="mini" type="text"-->
              <!--@click="replaceDialog(scope.$index, scope.row)">代付打款</el-button>-->
            <el-button v-if="$store.state.routes.routes.yhtxqxOperate"
              size="mini" type="text"
              @click="cancelDialog(scope.$index, scope.row)" :disabled="scope.row.state!=10">取消提现</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="limit"
                     :total="total" style="float:right;">
      </el-pagination>
    </el-row>

    <el-dialog title="手动打款" :visible.sync="handDialogVisible" width="30%" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="handForm" ref="editPwdForm" status-icon label-width="100px" style="text-align:left">
        <el-form-item label="用户名" >
          <el-col :span="22">
            <el-input v-model="handForm.username"  disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="姓名" >
          <el-col :span="22" >
            <el-input type="text" v-model="handForm.realname" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="手机号" >
          <el-col :span="22">
            <el-input type="text"  v-model="handForm.mobile" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="打款金额" >
          <el-col :span="22">
            <el-input type="text"  v-model="handForm.amount" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="银行" >
          <el-col :span="22">
            <el-input   v-model="handForm.bankCardbranch" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="银行卡号" >
          <el-col :span="22">
            <el-input  v-model="handForm.bankCardNo" disabled></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="handDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click.native="submitHandDialog" :loading="editPwdLoading">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="代付打款" :visible.sync="replaceDialogVisible" width="30%" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="handForm" ref="editPwdForm" status-icon label-width="100px" style="text-align:left">
        <el-form-item label="用户名" >
          <el-col :span="22">
            <el-input v-model="handForm.username"  disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="姓名" >
          <el-col :span="22" class="orderId">
            <el-input type="text" v-model="handForm.realname" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="手机号" >
          <el-col :span="22">
            <el-input type="text"  v-model="handForm.mobile" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="打款金额" >
          <el-col :span="22">
            <el-input type="text"  v-model="handForm.amount" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="打款方式" >
          <el-col :span="22">
            代付打款
          </el-col>
        </el-form-item>
        <el-form-item label="财务密码" >
          <el-col :span="22">
            <el-input type="password"  v-model="handForm.pwd" disabled></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="replaceDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click.native="submitReplaceDialog" :loading="editPwdLoading">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="审核" :visible.sync="checkDialogVisible" width="30%" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="handForm" ref="editPwdForm" status-icon label-width="100px" style="text-align:left">
        <el-form-item label="用户名" >
          <el-col :span="22">
            <el-input v-model="handForm.username"  disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="姓名" >
          <el-col :span="22" >
            <el-input type="text" v-model="handForm.realname" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="手机号" >
          <el-col :span="22">
            <el-input type="text"  v-model="handForm.mobile" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="打款余额" >
          <el-col :span="22">
            <el-input type="text"  v-model="handForm.amount" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="银行" >
          <el-col :span="22">
            <el-input   v-model="handForm.bankCardbranch" disabled></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="银行卡号" >
          <el-col :span="22">
            <el-input  v-model="handForm.bankCardNo" disabled></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="checkDialogVisible = false">拒 绝</el-button>
        <el-button type="primary" @click.native="submitCheckDialog" :loading="editPwdLoading">通 过</el-button>
      </div>
    </el-dialog>
  </div>

</template>
<script>
  export default {
    data() {
      return {
        options: [{
          value: '10',
          label: '未处理'
        }, {
          value: '15',
          label: '已处理'
        }, {
          value: '20',
          label: '已拒绝'
        }],
        filters:{
          begtime:'',
          endtime:''
        },
        handForm:{},
        replaceForm:{},
        listLoading:false,
        editPwdLoading:false,
        handDialogVisible:false,
        checkDialogVisible:false,
        replaceDialogVisible:false,
        limit:10,
        page:1,
        total:0,
        users:[]
      };
    },
    filters:{
      stateFormat(val){
        switch (val){
          case 10:
            return '未处理';
            break
          case 15:
            return '已处理';
            break
          case 20:
            return '拒绝';
            break
        }
      }
    },
    created() {
      this.getUsers()
    },
    methods: {
      getUsers(){
        this.users = []
        this.listLoading = true;
        var obj = {
          data:{
            keyword:this.filters.keyword,
            serialnumber:this.filters.serialnumber,
            state:10,
            orgin:this.filters.orgin,
            applyBegtime:this.filters.begtime==''||this.filters.begtime==0||this.filters.begtime==null?'':Math.round(new Date(this.filters.begtime).getTime()/1000),
            applyEndtime:this.filters.endtime==''||this.filters.endtime==0||this.filters.endtime==null?'':Math.round(new Date(this.filters.endtime).getTime()/1000),
            pageNo:this.page,
            orderCol:"applyTime"
          }
        };
        this.$http('sys/membercash/list.do',obj).then(resp => {
          if(resp.code==1){
            this.users = resp.data.list;
            this.total = resp.data.total;
          }
          this.listLoading = false;
        });
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getUsers();
      },
      handDialog(index,row){
        if(!this.$store.state.routes.routes.yhtxsdOperate){
          this.$message({
            message:'无权限',
            type:'error'
          })
          return
        }
        this.handForm = row
        this.handDialogVisible = true
      },
      submitHandDialog(){
        this.editPwdLoading = true
        this.$http('sys/membercash/handpay.do',{data:{id:this.handForm.id}}).then(resp => {
          if(resp.code==1){
            this.$message({
              message:resp.msg,
              type:'success'
            })
          }else{
            this.$message({
              message:resp.msg,
              type:'error'
            })
          }
          this.handDialogVisible = false;
          this.editPwdLoading = false;
          this.getUsers()
        });
      },
      replaceDialog(index,row){
        this.replaceForm = row
        this.handDialogVisible = true
      },
      submitReplaceDialog(){
        this.editPwdLoading = true
        this.$http('sys/membercash/handpay.do',{data:{id:this.replaceForm.userId}}).then(resp => {
          if(resp.code==1){
            this.$message({
              message:resp.msg,
              type:'error'
            })
          }else{
            this.$message({
              message:resp.msg,
              type:'error'
            })
          }
          this.handDialogVisible = false;
          this.editPwdLoading = false;
          this.getUsers()
        });
      },
      cancelDialog(index,row) {
        if(!this.$store.state.routes.routes.yhtxqxOperate){
          this.$message({
            message:'无权限',
            type:'error'
          })
          return
        }
        this.$confirm("是否取消用户的提现?", "提示", {})
          .then(() => {
            this.$http('sys/membercash/cancle.do',{data:{id:row.id}}).then(resp => {
              if(resp.code==1){
                this.$message({
                  message:resp.msg,
                  type:'success'
                })
              }else{
                this.$message({
                  message:resp.msg,
                  type:'error'
                })
              }
              this.getUsers()
            });
          })
          .catch(() => {});
      },

    }
  }
</script>

<style scoped>

  .absoSpan{
    position: absolute;
    left: -11px;
  }
</style>
